package com.sc.nft.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.annotation.UserLogin;
import com.sc.nft.annotation.UserRecordTimes;
import com.sc.nft.controller.request.GetDaoBannersRequest;
import com.sc.nft.controller.request.GetIncomeListNewVersionRequest;
import com.sc.nft.controller.request.GetIncomeListRequest;
import com.sc.nft.controller.request.GetUserDaoDetailsRequest;
import com.sc.nft.controller.request.GetUserDaoRequest;
import com.sc.nft.controller.vo.DaoBannerVO;
import com.sc.nft.dao.DaoBannerDao;
import com.sc.nft.dao.UserInfoDao;
import com.sc.nft.entity.vo.*;
import com.sc.nft.pool.UserPool;
import com.sc.nft.service.DaoService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 服务控制器
 *
 * @author Sun
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2022-05-29 10:36:55
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/dao")
@Api(tags = "dao页面")
public class DaoController {
    private final DaoService daoService;
    private final UserInfoDao userInfoDao;
    private final DaoBannerDao daoBannerDao;

    @ApiOperation(value = "banner列表", notes = "banner列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getBanners", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    @UserRecordTimes
    public Result<List<DaoBannerVO>> getBanners(@Valid @RequestBody GetDaoBannersRequest request) {
        return Result.successColl(daoBannerDao.getByDaoId(request.getId(),request.getPosition()),DaoBannerVO.class);
    }

    @ApiOperation(value = "用户Dao页面", notes = "用户Dao页面", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getUserDaoDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<UserDaoVO> getUserDaoDetails() {
        return Result.success(daoService.getUserDaoDetails(UserPool.getUser()));
    }

    @ApiOperation(value = "用户推荐列表", notes = "用户推荐列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getRecommendListByUser", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<UserDaoDetailVO> getRecommendListByUser(@Valid @RequestBody GetUserDaoRequest request) {
        Page page = daoService.getRecommendListByUser(UserPool.getUser().getId(), request.getTime(), request.getHoldToken(), request.getSecondaryHoldToken(), request.getPageNo(), request.getPageSize());
        return PageResult.success(page, UserDaoDetailVO.class);
    }

    @ApiOperation(value = "获取升级权益列表", notes = "获取升级权益列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getDaoLevelList", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<DaoLevelVO> getDaoLevelList() {
        return Result.success(daoService.getDaoLevelList());
    }


    @ApiOperation(value = "用户Dao页面(H5)", notes = "用户Dao页面(H5)", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getUserDaoDetailsByH5", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<UserDaoVO> getUserDaoDetailsByH5(@Valid @RequestBody GetUserDaoDetailsRequest request) {
        return Result.success(daoService.getUserDaoDetailsByH5(request.getId()));
    }


    @ApiOperation(value = "用户推荐列表(H5)", notes = "用户推荐列表(H5)", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getRecommendListByUserH5", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<UserDaoDetailVO> getRecommendListByUserH5(@Valid @RequestBody GetUserDaoRequest request) {
        Page page = daoService.getRecommendListByUserH5(request.getId(), request.getTime(), request.getHoldToken(), request.getSecondaryHoldToken(), request.getPageNo(), request.getPageSize());
        return PageResult.success(page, UserDaoDetailVO.class);
    }


    @ApiOperation(value = "用户收益详情(H5)", notes = "用户收益详情(H5)", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getIncomeDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<GetIncomeDetailsVO> getIncomeDetails() {
        return Result.success(daoService.getIncomeDetails());
    }

    @ApiOperation(value = "用户收益详情(H5)", notes = "用户收益详情(H5)", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getIncomeNewDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<GetIncomeDetailsVO> getIncomeNewDetails() {
        return Result.success(daoService.getIncomeNewDetails());
    }

    @ApiOperation(value = "用户收益列表(H5)新版本4.5.0", notes = "用户收益列表(H5)新版本4.5.0", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/v4.5.0/getIncomeList", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<IncomeDetailsVO> getIncomeListNewVersions(@Valid @RequestBody GetIncomeListNewVersionRequest request) {
        return PageResult.success(daoService.getIncomeListNewVersions(request.getIncomeHierarchyEnum(), request.getPageNo(), request.getPageSize()));
    }

    @ApiOperation(value = "用户收益列表(H5)", notes = "用户Dao页面(H5)", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getIncomeList", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<IncomeDetailsVO> getIncomeList(@Valid @RequestBody GetIncomeListRequest request) {
        return PageResult.success(daoService.getIncomeList(request.getIncomeHierarchyEnum(), request.getPageNo(), request.getPageSize()));
    }

}